package collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

//集合提供了一个方法，toArray方法，可以将集合转换为数组
public class CollectionToArrayDemo {
    public static void main(String[] args) {
        Collection <String >c=new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        System.out.println(c);
        String []arr1=c.toArray(new String[c.size()]);
        String []arr2=c.toArray(new String[10]);
        String []arr3=c.toArray(new String[0]);//很随和的编译器，自动banging，
        System.out.println(arr1.length);
        System.out.println(arr2.length);
        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));
        System.out.println(Arrays.toString(arr3));
    }
}
